package com.totoro.tymapping.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Totoro
 * @version 0.1.0
 * @date 2025/8/10 - 22:19
 * @description Tag-标签就是: {random:1-2}等等
 **/
public class TagUtil {

    /**
     * @author totoro
     * @description 获取某个字符串中的所有标签 {}
     * @date  22:20
     * @param [input]
     * @return java.util.List<java.lang.String>
     **/
    public static List<String> getTags(String input) {
        List<String> result = new ArrayList<>();
        Pattern pattern = Pattern.compile("\\{[^}]*\\}");
        Matcher matcher = pattern.matcher(input);
        while (matcher.find()) {
            result.add(matcher.group());
        }
        return result;
    }

    /**
     * @author totoro
     * @description 返回标签里的内容，就是去掉了{}
     * @date  22:24
     * @param [tag]
     * @return java.lang.String
     **/
    public static String getTagContent(String tag) {
        Pattern pattern = Pattern.compile("\\{(.*?)\\}");
        Matcher matcher = pattern.matcher(tag);
        if (matcher.find()) {
            return matcher.group(1);
        }
        return tag;
    }

}
